package vn.allmobile.happyvoucher.util;

 
import vn.allmobile.happyvoucher.model.Account;
import vn.allmobile.happyvoucher.model.Account.AccountType;
import android.content.Context;
public class LoginManager {
	
	 private boolean mIsAccountInited = false;
	 private LoginCallback mLoginCallback;	  
	 private Account mAcount;
	 private static LoginManager sLoginManager;
	 private Context mContext;
	 
	 public LoginManager(Context context) {
		 this.mContext = context;
		 this.mAcount = new Account();
	}
	 
	 

	public static LoginManager getManager()
	 {
	    return sLoginManager;
	 }

	  public static void init(Context context)
	 {
	    if (sLoginManager == null)
	      sLoginManager = new LoginManager(context);
	 }
	  
	  public void setAccount(Account account){
		  mAcount = account;
	  }
	  
	  public Account getAccount(){
		  return this.mAcount;
	  }
	  
 
	 @SuppressWarnings("deprecation")
	public boolean hasLogin()
	 {
		if(this.mAcount != null){
			if(this.mAcount.getmAccountType() == AccountType.FACEBOOK)
			{
				 return true;
			}
		}
		return false;
	 }
	 
	 public void onLoginSuccess(Account mAccount){
		 if(mAccount != null)
			 this.mLoginCallback.onLoginSucceed(mAccount);
		 else{
			 this.mLoginCallback.onLoginFailed();
		 }
	 }
	 
	
	 public void login(LoginCallback loginCallBack){		
	    this.mLoginCallback = loginCallBack;
	    if(!hasLogin()){
//	    	Intent loginActivity = new Intent(this.mContext,LoginActivity.class);
//	    	loginActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );	    	
//	    	loginActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );	    	
//	        this.mContext.startActivity(loginActivity);
	    }else
	    {
	    	onLoginSuccess(this.mAcount);
	    }
	 }
	 
	 public static abstract interface LoginCallback
	  {
	    public abstract void onLoginFailed();

	    public abstract void onLoginSucceed(Account mAccount);
	  }
}
